home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 1.iso
/
DEMON
/
RISCOS2
/
TCP_131S.ARC
/
c
/
arpcmd
< prev
next >
Wrap
Text File
|
1993-12-22
|
6KB
|
185 lines
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <time.h>
#include "global.h"
#include "mbuf.h"
#include "domain.h"
#include "timer.h"
#include "ax25.h"
#include "misc.h"
#include "arp.h"
#include "cmdparse.h"
#include "netuser.h"
extern char badhost[];
extern char nospace[];
static int doarpadd(int, char **);
static int doarpdrop(int, char **);
static int dumparp(void);
struct cmds arpcmds[] = {
"add", doarpadd, 4,
"arp add <hostid> ether|ax25|netrom <ether addr|callsign>",
"arp add failed",
"drop", doarpdrop, 3,
"arp drop <hostid> ether|ax25|netrom",
"not in table",
"publish", doarpadd, 4,
"arp publish <hostid> ether|ax25|netrom <ether addr|callsign>",
"arp add failed",
NULLCHAR, NULLFP, 0,
"arp subcommands: add, drop, publish",
NULLCHAR,
};
char *arptypes[] = {
"NET/ROM",
"10 Mb Ethernet",
"3 Mb Ethernet",
"AX.25",
"Pronet",
"Chaos",
"Arcnet",
"Appletalk"
};
int doarp(int argc, char **argv)
{
if(argc < 2){
dumparp();
return 0;
}
return subcmd(arpcmds,argc,argv);
}
static int doarpadd(int argc, char **argv)
{
int16 hwalen,hardware,naddr;
int32 addr;
char *hwaddr;
struct arp_tab *ap;
struct arp_type *at;
int pub = 0;
if(argv[0][0] == 'p') /* Is this entry published? */
pub = 1;
if((addr = resolve(argv[1])) == 0){
cwprintf(NULL, badhost,argv[1]);
return 1;
}
/* This is a kludge. It really ought to be table driven */
switch(tolower(argv[2][0])){
case 'n': /* Net/Rom pseudo-type */
hardware = ARP_NETROM;
naddr = argc - 3 ;
if (naddr != 1) {
cwprintf(NULL, "No digipeaters in NET/ROM arp entries - ") ;
cwprintf(NULL, "use netrom route add\r\n") ;
return 1 ;
}
break;
case 'a': /* "ax25" */
hardware = ARP_AX25;
naddr = argc - 3;
break;
default:
cwprintf(NULL, "unknown hardware type \"%s\"\r\n",argv[2]);
return -1;
}
/* If an entry already exists, clear it */
if((ap = arp_lookup(hardware,addr)) != NULLARP)
arp_drop(ap);
at = &arp_type[hardware];
if(at->scan == NULLFP){
cwprintf(NULL, "Attach device first\r\n");
return 1;
}
/* Allocate buffer for hardware address and fill with remaining args */
hwalen = at->hwalen * naddr;
if((hwaddr = malloc(hwalen)) == NULLCHAR){
cwprintf(NULL, nospace);
return 0;
}
/* Destination address */
(*at->scan)(hwaddr,&argv[3],argc - 3);
ap = arp_add(addr,hardware,hwaddr,hwalen,pub); /* Put in table */
free(hwaddr); /* Clean up */
stop_timer(&ap->timer); /* Make entry permanent */
ap->timer.count = ap->timer.start = 0;
return 0;
}
/* Remove an ARP entry */
static int doarpdrop(int argc, char **argv)
{
int16 hardware;
int32 addr;
struct arp_tab *ap;
argc = argc;
if((addr = resolve(argv[1])) == 0){
cwprintf(NULL, badhost,argv[1]);
return 1;
}
/* This is a kludge. It really ought to be table driven */
switch(tolower(argv[2][0])){
case 'n':
hardware = ARP_NETROM;
break;
case 'a': /* "ax25" */
hardware = ARP_AX25;
break;
default:
hardware = 0;
break;
}
if((ap = arp_lookup(hardware,addr)) == NULLARP)
return -1;
arp_drop(ap);
return 0;
}
/* Dump ARP table */
static int dumparp(void)
{
register int i;
extern struct arp_stat arp_stat;
register struct arp_tab *ap;
char e[128];
extern char *arptypes[];
cwprintf(NULL, "received %u badtype %u bogus addr %u reqst in %u replies %u reqst out %u\r\n",
arp_stat.recv,arp_stat.badtype,arp_stat.badaddr,arp_stat.inreq,
arp_stat.replies,arp_stat.outreq);
cwprintf(NULL, "IP addr Type Time Q Addr\r\n");
for(i=0;i<ARPSIZE;i++){
for(ap = arp_tab[i];ap != (struct arp_tab *)NULL;ap = ap->next){
cwprintf(NULL, "%-16s",inet_ntoa(ap->ip_addr));
cwprintf(NULL, "%-15s",arptypes[ap->hardware]);
cwprintf(NULL, "%-5ld",ap->timer.count*(long)MSPTICK/1000);
if(ap->state == ARP_PENDING)
cwprintf(NULL, "%-2u",len_q(ap->pending));
else
cwprintf(NULL, " ");
if(ap->state == ARP_VALID){
if(arp_type[ap->hardware].format != NULLFP){
(*arp_type[ap->hardware].format)(e,ap->hw_addr);
} else {
e[0] = '\0';
}
cwprintf(NULL, "%s",e);
} else {
cwprintf(NULL, "[unknown]");
}
if(ap->pub)
cwprintf(NULL, " (published)");
cwprintf(NULL, "\r\n");
}
}
return 0;
}